<template>
  <div class="app-container">
    <el-row>
      <el-col :span="24">
        <div class="h_top">
          <div class="bread_title">
            <span>新增供应商</span>
          </div>
          <div class="save_button">
            <div class="buttonBox">
              <el-button type="primary" icon="el-icon-back" size="mini" @click="goBack">返回</el-button>
            </div>
            <div class="buttonBox">
              <el-button type="primary" icon="el-icon-document-checked" size="mini" @click="save">保存</el-button>
            </div>
          </div>
        </div>
      </el-col>
    </el-row>
    <div>
      <el-row>
        <el-col :span="24">
          <el-form ref="form" :model="data" :inline="true" :rules="formRules">
            <el-row :gutter="10">
              <el-col :xl="6" :lg="6" :md="8" :sm="8">
                <el-form-item prop="coding">
                  <div>编号</div>
                  <el-input v-model="data.coding" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :xl="6" :lg="6" :md="8" :sm="8">
                <el-form-item prop="name">
                  <div>名称</div>
                  <el-input v-model="data.name" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :xl="6" :lg="6" :md="8" :sm="8">
                <el-form-item prop="phone">
                  <div>电话</div>
                  <el-input v-model="data.phone" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :xl="6" :lg="6" :md="8" :sm="8">
                <el-form-item prop="email">
                  <div>电子邮箱</div>
                  <el-input v-model="data.email" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :xl="6" :lg="6" :md="8" :sm="8">
                <el-form-item prop="address1">
                  <div>地址第1行</div>
                  <el-input v-model="data.address1" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :xl="6" :lg="6" :md="8" :sm="8">
                <el-form-item prop="address2">
                  <div>地址第2行</div>
                  <el-input v-model="data.address2" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :xl="6" :lg="6" :md="8" :sm="8">
                <el-form-item prop="zip">
                  <div>邮政编码</div>
                  <el-input v-model="data.zip" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :xl="3" :lg="3" :md="4" :sm="4">
                <el-form-item prop="city">
                  <div>城市</div>
                  <el-input v-model="data.city" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :xl="4" :lg="3" :md="8" :sm="8">
                <el-form-item prop="country">
                  <div>国家</div>
                  <el-input v-model="data.country" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :xl="8" :lg="8" :md="12" :sm="8">
                <el-form-item prop="weburl">
                  <div>网站</div>
                  <el-input v-model="data.weburl" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :xl="6" :lg="6" :md="8" :sm="8">
                <el-form-item prop="sort">
                  <div>排序</div>
                  <el-input v-model="data.sort" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :xl="8" :lg="8" :md="10" :sm="10">
                <el-form-item>
                  <div>选项</div>
                  <el-checkbox v-model="data.is_provider" label="是供应商" :true-label="1" :false-label="0" size="mini" />
                  <el-checkbox v-model="data.is_manufacturer" label="是制造商" :true-label="1" :false-label="0" size="mini" />
                  <el-checkbox v-model="data.is_epiboly" label="是外包商" :true-label="1" :false-label="0" size="mini" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <el-tabs>
            <el-tab-pane label="描述">
              <el-row :gutter="10">
                <el-col :span="24">
                  <Tinymce id="content" v-model="data.content" />
                </el-col>
              </el-row>
            </el-tab-pane>
          </el-tabs>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import API from '@/api/system/provider'
import Tinymce from '@/components/Tinymce/index'
export default {
  inject: ['addOne', 'goUrl'],
  components: {
    Tinymce
  },
  data() {
    return {
      data: {
        coding: '',
        name: '',
        phone: '',
        email: '',
        address1: '',
        address2: '',
        zip: '',
        city: '',
        country: '',
        weburl: '',
        sort: 100
      },
      formRules: {
        coding: [
          {
            required: true,
            message: '请输入编号',
            trigger: 'blur'
          }
        ],
        name: [
          {
            required: true,
            message: '请输入供应商名称',
            trigger: 'blur'
          }
        ],
        phone: [
          {
            required: true,
            message: '请输入电话',
            trigger: 'blur'
          }
        ],
        email: [
          {
            required: true,
            message: '请输入电子邮箱',
            trigger: 'blur'
          }
        ],
        country: [
          {
            required: true,
            message: '请输入国家',
            trigger: 'blur'
          }
        ],
        sort: [
          {
            required: true,
            message: '请输入排序',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  created() {
  },
  methods: {
    save() {
      const thisData = this.data
      const thisForm = this.$refs.form
      this.addOne(API, thisData, thisForm)
    },
    goBack() {
      this.goUrl('/system/provider')
    }
  }
}
</script>
